<?php
!defined('P_W') && exit('Forbidden');
/**
 *
 * 二手房个人信息db类
 * @author hu.liaoh
 *
 */
class PW_House_PersonalDB extends BaseDB {

	var $_tableName = 'pw_house_personal';
	var $_primaryKey = 'houseid';
	
	/**
	 *
	 * 根据houseid获取一条记录
	 * @param int $houseid
	 */
	function get($houseid){
		return $this->_get($houseid);
	}
	
	/**
	 * 
	 * 增加一条记录
	 * @param array $data 房源信息
	 */
	function add($data){
		$_sql = 'INSERT INTO ' . $this->_tableName .' SET '. pwSqlSingle($data) ;
		$this->_db->update($_sql);
		return $this->_db->insert_id();	
	}
	
	/**
	 * 
	 * 根据houseid更新一条记录
	 * @param int $houseid
	 */
	function update($data, $houseids){
		!is_array($houseids) && $houseids = array($houseids);
		if(empty($houseids)) return array();
		$_sql = 'UPDATE ' . $this->_tableName . ' SET ' . $this->_getUpdateSqlString($data) . ' WHERE ' . $this->_primaryKey . ' IN (' . pwImplode($houseids). ')';
		return $this->_db->query($_sql);
	}	
	
	/**
	 * 
	 * 根据houseid删除一条或者多条记录
	 * @param int $houseid
	 */
	function delete($houseids, $type){
		!is_array($houseids) && $houseids = array($houseids);
		if(empty($houseids)) return array();
		$_sql = 'DELETE FROM ' . $this->_tableName . ' WHERE datatype= '.pwEscape($type) .' AND '. $this->_primaryKey .' IN (' . pwImplode($houseids) . ')';
		return $this->_db->query($_sql);
	}

	/**
	 * 
	 * 获取表数据结构
	 */
	function getStruct($type='add'){
		$struct = array('add'=>array('houseid', 'datatype', 'linkman', 'phone', 'tel', 'email'),
						'update'=> array('linkman', 'phone', 'tel', 'email'));
		return $struct[$type] ? $struct[$type] : array();
	}
	}
?>